import 'package:flutter/material.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/config/router_config.dart';
import 'package:s_mankey/service/smonkey_repository.dart';
import 'package:s_mankey/ui/widget/error_widget.dart';
import 'package:s_mankey/ui/widget/loading_widget.dart';

class InviteRecord extends StatefulWidget {

  final arguments;

  const InviteRecord({Key key, this.arguments}) : super(key: key);

  @override
  _InviteRecord createState() => _InviteRecord();
}

class _InviteRecord extends State<InviteRecord> {
  List datas;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('邀请记录'),
        elevation: 0,
      ),
      body: Container(
        margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
        padding: EdgeInsets.all(
          10,
        ),
        child: FutureBuilder(future: SmonkeysRepository.fetchMyInvitationHistory(),builder:
    (BuildContext context, AsyncSnapshot snapshot) {

    /// 请求中
    if (snapshot.connectionState != ConnectionState.done) {
    return LoadingWidget();
    }
    /// 请求结束
    if (snapshot.hasError) {
    // 请求失败，显示错误
    return datasErrorWidget(errorTip: snapshot.error.toString(),);
    }
    datas = snapshot.data;
    // 请求成功，显示数据
    return

        ListView.builder(
            itemCount: datas.length,
            itemBuilder: (BuildContext context, int index) {
              return GestureDetector(
                onTap: () {
                  Navigator.pushNamed(context, RouterName.inviteDetail,arguments: datas[index]['id']);
                },
                child: Container(
                  margin: EdgeInsets.only(top: 10),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(10)),
                  child: Column(
                    children: [
                      //姓名
                      Padding(
                        padding: const EdgeInsets.all(10),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              datas[index]['chi_name_s'],
                              style: TextStyle(fontSize: AppFontSize.Size16),
                            ),
                            Row(
                              children: [
                                Text(
                                  '已失效',
                                  style:
                                      TextStyle(fontSize: AppFontSize.Size14),
                                ),
                                IconFonts.rightIcon
                              ],
                            )
                          ],
                        ),
                      ),

                      //分割线
                      Container(
                        color: AppColor.dividerColor,
                        height: 1,
                      ),
                      //内容
                      listCell(
                          title: datas[index]['course_name'],
                          des: datas[index]['course_time']),
                      listCell(title: '上课城市', des: datas[index]['city']),
                      listCell(title: '送出盛点数', des: datas[index]['miles']),
                    ],
                  ),
                ),
              );
            });}),
      ),
    );
  }

  Widget listCell({String title, String des}) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(10, 8, 10, 8),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            title,
            style: TextStyle(fontSize: AppFontSize.Size14),
          ),
          Text(
            des,
            style: TextStyle(fontSize: AppFontSize.Size14),
          ),
        ],
      ),
    );
  }
}
